﻿using Abp.Domain.Repositories;
using AppFramework.DinosaursParkMes.Material;
using AppFramework.DinosaursParkMes.Material.Dto;
using AppFramework.DinosaursParkMes.ProductWork;
using AppFramework.DinosaursParkMes.ProductWork.Dto;
using AppFramework.DinosaursParkMes.TicketTask;
using AppFramework.DinosaursParkMes.WorkOrder;
using AppFramework.DinosaursParkMes.WorkOrder.CodingPush;
using AppFramework.Dto;
using AppFramework.Storage;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace AppFramework.Web.Controllers.CodingExcelPush
{
    [Route("api/[controller]")]
    [ApiController]
    public class CodingExcelController : AppFrameworkControllerBase
    {
        private readonly IWorkOrderAppService _workOrderAppService;
        private readonly ITempFileCacheManager _tempFileCacheManager;
        private readonly IMaterialAppService materialAppService;
        private readonly ITicketTaskinfoAppService ticketTaskinfoAppService;
        

        public CodingExcelController(IWorkOrderAppService workOrderAppService, ITempFileCacheManager tempFileCacheManager, IMaterialAppService materialAppService, ITicketTaskinfoAppService ticketTaskinfoAppService = null)
        {
            _workOrderAppService = workOrderAppService;
            _tempFileCacheManager = tempFileCacheManager;
            this.materialAppService = materialAppService;
            this.ticketTaskinfoAppService = ticketTaskinfoAppService;
        }
        /// <summary>
        /// 编号导出
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("CodingFile")]
        public IActionResult CodingFile()
        {
            var file = _workOrderAppService.GetFile();
            byte[] data = _tempFileCacheManager.GetFile(file.Result.FileToken);
            return File(data,file.Result.FileType,file.Result.FileName);
        }
        /// <summary>
        /// 物料导出
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("download")]
        public IActionResult download()
        {
            var file = materialAppService.GetFileDto();
            byte[] data = _tempFileCacheManager.GetFile(file.Result.FileToken);
            return File(data, file.Result.FileType, file.Result.FileName);
        }
        /// <summary>
        /// 工单导出
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("GetProductWorkModelsFile")]
        public  IActionResult GetProductWorkModelsFile()
        {
            var file = materialAppService.GetProductWorkModelsFile();
            byte[] data = _tempFileCacheManager.GetFile(file.Result.FileToken);
            return File(data, file.Result.FileType, file.Result.FileName);
        }
        /// <summary>
        /// 工单任务导出
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("GetFileTicketTask")]
        public IActionResult GetFileTicketTask()
        {
            var file = ticketTaskinfoAppService.GetFileTicketTask();
            byte[] data = _tempFileCacheManager.GetFile(file.Result.FileToken);
            return File(data, file.Result.FileType, file.Result.FileName);
        }

    }

}
